#ifndef __packet_util_
#define __packet_util_ 1

#define MAC_FMT "%02x:%02x:%02x:%02x:%02x:%02x"
#define MAC_PRINT(x)   (uint8_t)x[0],(uint8_t)x[1],(uint8_t)x[2],\
                        (uint8_t)x[3],(uint8_t)x[4],(uint8_t)x[5]
#define IP_FMT "%u.%u.%u.%u"
#define IP_PRINT(x)     (((x)>>24 )& 0xff), (((x)>>16 )& 0xff), (((x)>>8 )& 0xff),(((x)>>0 )& 0xff)

#define PRINT_PACKET(pkt)   do{\
                                log_trace("============================");\
                                log_trace("MAC dest: "MAC_FMT", src: "MAC_FMT, MAC_PRINT(pkt->eth_hdr->h_dest), MAC_PRINT(pkt->eth_hdr->h_source));\
                                if(pkt->ip_hdr){\
                                    log_trace("IP dest: "IP_FMT", src: "IP_FMT, IP_PRINT(ntohl(pkt->ip_hdr->daddr)), IP_PRINT(ntohl(pkt->ip_hdr->saddr)));\
                                    if(pkt->udp_hdr){\
                                        log_trace("UDP dport: %u, sport: %u", ntohs(pkt->udp_hdr->dest), ntohs(pkt->udp_hdr->source));\
                                    }\
                                    if(pkt->tcp_hdr){\
                                        log_trace("TCP dport: %u, sport: %u", ntohs(pkt->tcp_hdr->dest), ntohs(pkt->tcp_hdr->source));\
                                    }\
                                    if(pkt->icmp_hdr){\
                                        log_trace("ICMP type:%u, id:%u", pkt->icmp_hdr->icmp_type, pkt->icmp_hdr->icmp_id);\
                                    }\
                                }\
                                log_trace("============================");\
                            }while(0) 

#endif